package app.species.ANN;

import java.io.*;
import ec.util.MersenneTwisterFast;

class TestNet implements Serializable{

	private static final long serialVersionUID = 1L;

	public static void main(String args[]) throws Exception{

		MersenneTwisterFast random = new MersenneTwisterFast();

		SomaChromosome sChrome = new SomaChromosome();
		AxonChromosome aChrome = new AxonChromosome();
		SomaGene sGene;
		AxonGene aGene;
		Brain brain1, brain2, brain3;
		double[] output;

		sGene = new SomaGene(1, SomaGene.BIAS);
		sChrome.addGene(sGene);
		sGene = new SomaGene(2, SomaGene.INPUT);
		sChrome.addGene(sGene);
		sGene = new SomaGene(3, SomaGene.INPUT);
		sChrome.addGene(sGene);
		sGene = new SomaGene(4, SomaGene.INPUT);
		sChrome.addGene(sGene);
		sGene = new SomaGene(5, SomaGene.HIDDEN);
		sChrome.addGene(sGene);
		sGene = new SomaGene(6, SomaGene.OUTPUT);
		sChrome.addGene(sGene);

		aGene = new AxonGene(1, 1, 5, 0.4);
		aChrome.addGene(aGene);
		aGene = new AxonGene(2, 2, 5, 0.3);
		aChrome.addGene(aGene);
		aGene = new AxonGene(3, 3, 5, 0.2);
		aChrome.addGene(aGene);
		aGene = new AxonGene(4, 4, 5, 0.7);
		aChrome.addGene(aGene);
		aGene = new AxonGene(5, 1, 6, 0.7);
		aChrome.addGene(aGene);
		aGene = new AxonGene(6, 5, 6, 0.9);
		aChrome.addGene(aGene);
		aGene = new AxonGene(7, 6, 5, 0.3);
		aChrome.addGene(aGene);

		/*sGene = new SomaGene(1, SomaGene.INPUT);
		sChrome.addGene(sGene);
		sGene = new SomaGene(2, SomaGene.OUTPUT);
		sChrome.addGene(sGene);
		aGene = new AxonGene(1, 1, 2, 0.7);
		aChrome.addGene(aGene);*/

		brain1 = new AdamBrain(sChrome, aChrome, random);

		sChrome = new SomaChromosome();
		aChrome = new AxonChromosome();
		sGene = new SomaGene(1, SomaGene.BIAS);
		sChrome.addGene(sGene);
		sGene = new SomaGene(2, SomaGene.INPUT);
		sChrome.addGene(sGene);
		sGene = new SomaGene(3, SomaGene.INPUT);
		sChrome.addGene(sGene);
		sGene = new SomaGene(4, SomaGene.INPUT);
		sChrome.addGene(sGene);
		sGene = new SomaGene(5, SomaGene.HIDDEN);
		sChrome.addGene(sGene);
		sGene = new SomaGene(6, SomaGene.OUTPUT);
		sChrome.addGene(sGene);

		aGene = new AxonGene(1, 1, 5, 0.4);
		aChrome.addGene(aGene);
		aGene = new AxonGene(2, 2, 5, 0.3);
		aChrome.addGene(aGene);
		aGene = new AxonGene(3, 3, 5, 0.2);
		aChrome.addGene(aGene);
		aGene = new AxonGene(4, 4, 5, 0.7);
		aChrome.addGene(aGene);
		aGene = new AxonGene(5, 1, 6, 0.7);
		aChrome.addGene(aGene);
		aGene = new AxonGene(7, 6, 5, 0.3);
		aChrome.addGene(aGene);

		brain2 = new AdamBrain(sChrome, aChrome, random);

		for(int j = 0; j < 5; j++){

			output = brain1.activate(new double[]{.5, -.3, .8});

			for(int i = 0; i < output.length; i++){
				System.out.print(output[i] + " ");
			}
			System.out.println();
		}

		for(int j = 0; j < 5; j++){

			output = brain2.activate(new double[]{.5, -.3, .8});

			for(int i = 0; i < output.length; i++){
				System.out.print(output[i] + " ");
			}
			System.out.println();
		}

		brain3 = brain1.merge(brain2);

		for(int j = 0; j < 5; j++){

			output = brain3.activate(new double[]{.5, -.3, .8});

			for(int i = 0; i < output.length; i++){
				System.out.print(output[i] + " ");
			}
			System.out.println();
		}

	}

}
